package com.mpyy.handler.systemSetting;

import com.alibaba.fastjson.JSON;
import com.mpyy.dao.ToolsInter;
import com.mpyy.pojo.DepotInfo;
import com.mpyy.pojo.EmployeeInfo;
import com.mpyy.service.systemSetting.DepotInfoInter;
import com.mpyy.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * @version 1.0
 * @Description
 * @Author zhangkaibo
 * @Date 2022-03-22 11:22
 */
@Controller
public class DepotInfoHandler {
    @Autowired
    private DepotInfoInter depotInfoInter;

    @Autowired
    private ToolsInter toolInter;
    //仓库信息查询
    @RequestMapping(value = {"/searchDepotInfos"})
    @ResponseBody
    public String searchDepotInfo(){
        //System.out.println("调用仓库查询方法")
        List<DepotInfo> DepotInfos =  depotInfoInter.searchDepotInfo();
        HashMap<Object, Object> inventoryCollectMap = new HashMap<>();
        System.out.println(DepotInfos);
        inventoryCollectMap.put("code",0);
        inventoryCollectMap.put("msg","");
        inventoryCollectMap.put("count",DepotInfos.size());
        inventoryCollectMap.put("data",DepotInfos);
        return JSON.toJSONString(inventoryCollectMap);
    }
    //负责人查询
    @RequestMapping(value = {"/searchEmpName"})
    @ResponseBody
    public String searchEmpName(){
        System.out.println("调用查询负责人方法");
        List<EmployeeInfo> employeeInfos = depotInfoInter.searchEmpName();
        return JSON.toJSONString(employeeInfos);
    }
    //新增仓库信息
    @RequestMapping(value = {"/insertDepotInfo"})
    @ResponseBody
    private  String insertDepotInfo(DepotInfo depotInfo){

        depotInfo.setDepotId(new Tool().aotomaticId("depotId","depot_info",toolInter));
        System.out.println("invoke insertDepotInfo method"+depotInfo);
        int i = depotInfoInter.insertDepotInfo(depotInfo);
        return JSON.toJSONString(i);
    }
    //删除仓库信息
    @RequestMapping(value = {"/deleteDepotInfo"})
    @ResponseBody
    public int deleteDepotInfo(DepotInfo depotInfo){
        System.out.println(depotInfo.getDepotId());
        int i = depotInfoInter.deleteDepotInfo(depotInfo);
        return i;
    }
    //修改仓库信息
    @RequestMapping(value = {"/updateDepotInfo"})
    @ResponseBody
    public int updateDepotInfo(DepotInfo depotInfo){
        int i = depotInfoInter.updateDepotInfo(depotInfo);
        return i;
    }
}
